#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=250000, maxm=500000;

int min(int a, int b) {
  return a<b ? a : b;
}

class Graph {
public:
  int n, m, ind[2*maxm+1], to[2*maxn+1], link[2*maxn+1], dfn[2*maxm+1], low[2*maxm+1], col[2*maxm+1], in[2*maxm+1];
  bool vis[2*maxm+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
    ++in[v];
  }

  void tarjan(int o) {
    static int s[2*maxm+1];
    static bool book[2*maxm+1];
    low[o] = dfn[o] = ++dfn[0];
    s[++s[0]] = o;
    book[o] = vis[o] = true;
    for (int i=ind[o]; i; i=link[i]) {
      if (!vis[to[i]]) {
        tarjan(to[i]);
        low[o] = min(low[o], low[to[i]]);
      } else if (book[to[i]]) {
        low[o] = min(low[o], dfn[to[i]]);
      }
    }

    if (low[o]==dfn[o]) {
      ++col[0];
      for (; s[s[0]]!=o; --s[0]) {
        col[s[s[0]]] = col[0];
        book[s[s[0]]] = false;
      }
      col[s[s[0]]] = col[0];
      book[s[s[0]]] = false;
      --s[0];
    }
  }

  void genNew(Graph &g) {
    g.n = col[0];
    for (int i=1; i<=n; i++) {
      for (int j=ind[i]; j; j=link[j]) {
        if (col[to[j]]!=col[i]) {
          g.addSide(col[i], col[to[j]]);
        }
      }
    }
  }

  void sort(int q[]) {
    q[0] = 0;
    for (int i=1; i<=n; i++) {
      if (!in[i]) {
        q[++q[0]] = i;
      }
    }

    int h, t;
    for (h=0, t=q[0]; h<t; ) {
      int x=q[++h];
      for (int i=ind[x]; i; i=link[i]) {
        in[to[i]]--;
        if (!in[to[i]]) {
          q[++t] = to[i];
        }
      }
    }
    q[0] = t;
  }
};

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static Graph g, ng, grp;
  int n, m;
  scanf("%d %d", &n, &m);
  g.n = 2*m;
  for (int i=1; i<=n; ++i) {
    int a, sa, b, sb;
    scanf("%d %d %d %d", &a, &sa, &b, &sb);
    g.addSide(a*2-1+sa, b*2-sb);
    g.addSide(b*2-1+sb, a*2-sa);
  }
  for (int i=1; i<=2*m; ++i) {
    if (!g.vis[i]) g.tarjan(i);
  }

  for (int i=1; i<=m; ++i) {
    if (g.col[i*2]==g.col[i*2-1]) {
      printf("IMPOSSIBLE");
      return 0;
    }
    grp.addSide(g.col[i*2-1], i*2-1);
    grp.addSide(g.col[i*2], i*2);
  }
  g.genNew(ng);

  static int q[maxm*2+1], ans[maxm+1];
  ng.sort(q);
  for (int i=1; i<=q[0]; i++) {
    for (int j=grp.ind[q[i]]; j; j=grp.link[j]) {
      ans[(j+1)/2] = j%2;
    }
  }
  for (int i=1; i<=m; ++i) {
    printf("%d\n", ans[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
